#!/usr/bin/env bash

#http://www.computerhope.com/unix/udate.htm
#http://superuser.com/questions/707261/shell-script-bash-moving-file-iterate-based-on-month

numfiles=$#
echo "Moving $numfiles Files"

for file in "$@"; do
  year="$(date -d "$(stat -c %y "$file")" +%Y)"
  month="$(date -d "$(stat -c %y "$file")" +%m)"
  day="$(date -d "$(stat -c %y "$file")" +%d)"

#  echo $year, $month, $day
  DIR=$year$month$day
  if [ ! -d "$DIR" ]; then
    mkdir $DIR
  fi

  echo "Moving $file to $DIR"
  mv "$file" "$DIR"
done
